package cn.zf;

import java.text.SimpleDateFormat;
import java.util.*;

public class Job1 {
    //String file = "c:/user/abc/upload/xxsfasf.afasf-asfas.jpg";
//求出文件目录 c:/user/abc/upload/
//求出文件名称 xxsfasf.afasf-asfas.jpg
//求出文件的扩展名 jpg
//将字符串替换为c:/user/abc/upload/20211202154333.jpg
    public static void main(String[] args) {
        String file = "c:/user/abc/upload/xxsfasf.afasf-asfas.jpg";
        //求出文件目录 c:/user/abc/upload/
        System.out.println(file.substring(file.lastIndexOf(file),file.lastIndexOf("/")+1));
        //求出文件名称 xxsfasf.afasf-asfas.jpg
        System.out.println(file.substring(file.lastIndexOf("/")+1));
        //求出文件的扩展名 jpg
        System.out.println(file.substring(file.lastIndexOf(".")+1));
        //将字符串替换为c:/user/abc/upload/20211202154333.jpg
        var c=new SimpleDateFormat("yyyyMMddHHmmssS");
        Random r=new Random();
        //System.out.println(file.substring(file.lastIndexOf("/")+1,file.lastIndexOf(".")));
        String m= String.format("%s_%d",c.format(new Date()),r.nextInt(1,999999));
        String cc=file.replace(file.substring(file.lastIndexOf("/")+1,file.lastIndexOf(".")),m);
        System.out.println(cc);
        var u= UUID.randomUUID().toString().toLowerCase();
        String ff2=file.replace(file.substring(file.lastIndexOf("/")+1,file.lastIndexOf(".")),u);
        System.out.println(ff2);
    }

}
